In [183]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import collections as matcoll
import seaborn
seaborn.set(font_scale = 2)

import scipy.stats as stats
from sklearn import preprocessing

Stock Price Data

In [2]:
price = pd.read_csv("Stock Prices.csv",index_col='Date', parse_dates=True, dayfirst=True)
In [3]:
price.head()
Out[3]:
ATVI TTWO GME ZNGA
Date
2018-03-09 76.694267 116.610001 14.185772 3.72
2018-03-12 75.360802 115.739998 13.917271 3.75
2018-03-13 74.448944 113.489998 13.970971 3.70
2018-03-14 72.772293 109.230003 13.836721 3.77
2018-03-15 71.948677 108.900002 13.702471 3.86
In [4]:
price.plot(figsize=(20,10), linewidth = 2, color = ['royalblue', 'darkorchid', 'salmon', 'red'])
plt.title("Line Chart for Stock Prices", fontsize=30)
plt.xlabel("Date", fontsize = 25)
plt.ylabel("Price", fontsize = 25)
plt.legend(prop={'size': 25})
Out[4]:
<matplotlib.legend.Legend at 0x2b72c02b790>

Return Data

In [5]:
df = pd.read_csv("Data.csv",index_col='Date', parse_dates=True, dayfirst=True)
df.head()
Out[5]:
ATVI TTWO GME ZNGA
Date
2018-03-12 -0.010127 -0.004324 -0.011033 0.004637
2018-03-13 -0.012174 -0.019632 0.003851 -0.013423
2018-03-14 -0.022778 -0.038259 -0.009656 0.018742
2018-03-15 -0.011382 -0.003026 -0.009750 0.023592
2018-03-16 -0.023440 -0.014895 0.007159 -0.010417
In [6]:
df['ATVI'].plot(figsize=(20,10), linewidth = 2, color = ['royalblue'])
plt.title("Line Chart for ATVI Returns", fontsize=30)
plt.ylabel("Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[6]:
Text(0.5, 0, 'Date')
In [7]:
df['TTWO'].plot(figsize=(20,10), linewidth = 2, color = ['darkorchid'])
plt.title("Line Chart for TTWO Returns", fontsize=30)
plt.ylabel("Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[7]:
Text(0.5, 0, 'Date')
In [8]:
df['GME'].plot(figsize=(20,10), linewidth = 2, color = ['salmon'])
plt.title("Line Chart for GME Returns", fontsize=30)
plt.ylabel("Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[8]:
Text(0.5, 0, 'Date')
In [9]:
df['ZNGA'].plot(figsize=(20,10), linewidth = 2, color = ['red'])
plt.title("Line Chart for ZNGA Returns", fontsize=30)
plt.ylabel("Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[9]:
Text(0.5, 0, 'Date')

Serial Correlation

In [10]:
auto_corr = pd.DataFrame()
auto_corr['S_No'] = list(range(1,101))
In [11]:
auto_corr["ATVI"] = [df["ATVI"].autocorr(lag = i) for i in range(1,101)]
auto_corr["TTWO"] = [df["TTWO"].autocorr(lag = i) for i in range(1,101)]
auto_corr["GME"] = [df["GME"].autocorr(lag = i) for i in range(1,101)]
auto_corr["ZNGA"] = [df["ZNGA"].autocorr(lag = i) for i in range(1,101)]
In [12]:
auto_corr.head()
Out[12]:
S_No ATVI TTWO GME ZNGA
0 1 -0.124224 -0.158602 0.001830 -0.062703
1 2 -0.010887 0.019301 0.112558 0.006106
2 3 0.037628 -0.015828 0.205882 -0.051267
3 4 -0.052022 -0.025767 -0.260245 0.000738
4 5 -0.084707 -0.095740 0.039665 -0.063475
In [13]:
plt.figure(figsize=(20,10))
auto_corr["ATVI"].plot(color = 'royalblue')
plt.axhline(y=0, color='k', linestyle='--')
plt.title("ATVI: Autocorrelation vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
Out[13]:
Text(0, 0.5, 'Autocorrelation')
In [14]:
plt.figure(figsize=(20,10))
auto_corr["TTWO"].plot(color = 'darkorchid')
plt.axhline(y=0, color='k', linestyle='--')
plt.title("TTWO: Autocorrelation vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
Out[14]:
Text(0, 0.5, 'Autocorrelation')
In [15]:
plt.figure(figsize=(20,10))
auto_corr["GME"].plot(color = "salmon")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("GME: Autocorrelation vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
Out[15]:
Text(0, 0.5, 'Autocorrelation')
In [16]:
plt.figure(figsize=(20,10))
auto_corr["ZNGA"].plot(color = "red")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("ZNGA: Autocorrelation vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
Out[16]:
Text(0, 0.5, 'Autocorrelation')
In [17]:
from statsmodels.regression.linear_model import OLS
from statsmodels.stats.stattools import durbin_watson

def dw(data):
    ols_res = OLS(data, np.ones(len(data))).fit()
    return durbin_watson(ols_res.resid)

#which should not be correlated, thus giving a value close to 2
print("DW of ATVI = %f" % dw(df["ATVI"]))
print("DW of TTWO = %f" % dw(df["TTWO"]))
print("DW of GME = %f" % dw(df["GME"]))
print("DW of ZNGA = %f" % dw(df["ZNGA"]))
DW of ATVI = 2.248083
DW of TTWO = 2.317099
DW of GME = 1.996274
DW of ZNGA = 2.125236

Squared Returns Analysis

In [18]:
df_sq = pd.DataFrame()

for column in df.columns:
    df_sq[column] = df[column]**2
In [19]:
#which should not be correlated, thus giving a value close to 2
print("DW of ATVI = %f" % dw(df_sq["ATVI"]))
print("DW of TTWO = %f" % dw(df_sq["TTWO"]))
print("DW of GME = %f" % dw(df_sq["GME"]))
print("DW of ZNGA = %f" % dw(df_sq["ZNGA"]))
DW of ATVI = 1.808108
DW of TTWO = 1.685709
DW of GME = 1.315712
DW of ZNGA = 1.731361
In [20]:
len(df_sq["ATVI"])
Out[20]:
757
In [21]:
auto_corr_sq = pd.DataFrame()
auto_corr_sq['S_No'] = list(range(1,101))

auto_corr_sq["ATVI"] = [df_sq["ATVI"].autocorr(lag = i) for i in range(1,101)]
auto_corr_sq["TTWO"] = [df_sq["TTWO"].autocorr(lag = i) for i in range(1,101)]
auto_corr_sq["GME"] = [df_sq["GME"].autocorr(lag = i) for i in range(1,101)]
auto_corr_sq["ZNGA"] = [df_sq["ZNGA"].autocorr(lag = i) for i in range(1,101)]
In [22]:
plt.figure(figsize=(20,10))
auto_corr_sq["ATVI"].plot(color = "royalblue")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("ATVI: Autocorrelation - Squared Returns vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
Out[22]:
Text(0, 0.5, 'Autocorrelation')
In [23]:
plt.figure(figsize=(20,10))
auto_corr_sq["TTWO"].plot(color = "darkorchid")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("TTWO: Autocorrelation - Squared Returns vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
Out[23]:
Text(0, 0.5, 'Autocorrelation')
In [24]:
plt.figure(figsize=(20,10))
auto_corr_sq["GME"].plot(color = "salmon")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("GME: Autocorrelation - Squared Returns vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
Out[24]:
Text(0, 0.5, 'Autocorrelation')
In [25]:
plt.figure(figsize=(20,10))
auto_corr_sq["ZNGA"].plot(color = "red")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("ZNGA: Autocorrelation - Squared Returns vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
Out[25]:
Text(0, 0.5, 'Autocorrelation')

plotting

In [26]:
df_sq['ATVI'].plot(figsize=(20,10), linewidth = 2, color = ['royalblue'])
plt.title("Line Chart for ATVI Squared Returns", fontsize=30)
plt.ylabel("Squared Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[26]:
Text(0.5, 0, 'Date')
In [27]:
#ATVI
slope, intercept, r_value, p_value, std_err = stats.linregress(df_sq['ATVI'].shift(1)[1:],df_sq['ATVI'][1:])

abline_values = [slope * i + intercept for i in df_sq['ATVI'].shift(1)]

plt.figure(figsize=(20,10))
plt.scatter(df_sq['ATVI'].shift(1),df_sq['ATVI'], color = "royalblue")
plt.title("ATVI Day t Squared Return vs Day t-1 Squared Return", fontsize = 30)
plt.ylabel("Day t Squared Return", fontsize = 25)
plt.xlabel("Day t-1 Squared Return", fontsize = 25)
plt.plot(df_sq['ATVI'].shift(1), abline_values, 'k--', linewidth = 0.75)
Out[27]:
[<matplotlib.lines.Line2D at 0x2b72e8809a0>]
In [28]:
#ATVI
print("slope = ", slope)
print("intercept = ", intercept)
print("r_squared = ", r_value**2)
print("p_value = ", p_value)
slope =  0.09580268881924744
intercept =  0.0004166371260725805
r_squared =  0.00917742406670262
p_value =  0.008395421713047203
In [29]:
df_sq['TTWO'].plot(figsize=(20,10), linewidth = 2, color = ['darkorchid'])
plt.title("Line Chart for TTWO Squared Returns", fontsize=30)
plt.ylabel("Squared Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[29]:
Text(0.5, 0, 'Date')
In [30]:
#TTWO
slope, intercept, r_value, p_value, std_err = stats.linregress(df_sq['TTWO'].shift(1)[1:],df_sq['TTWO'][1:])

abline_values = [slope * i + intercept for i in df_sq['TTWO'].shift(1)]

plt.figure(figsize=(20,10))
plt.scatter(df_sq['TTWO'].shift(1),df_sq['TTWO'], color = "darkorchid")
plt.title("TTWO Day t Squared Return vs Day t-1 Squared Return", fontsize = 30)
plt.ylabel("Day t Squared Return", fontsize = 25)
plt.xlabel("Day t-1 Squared Return", fontsize = 25)
plt.plot(df_sq['TTWO'].shift(1), abline_values, 'k--', linewidth = 0.75)
Out[30]:
[<matplotlib.lines.Line2D at 0x2b72e94edf0>]
In [31]:
#TTWO
print("slope = ", slope)
print("intercept = ", intercept)
print("r_squared = ", r_value**2)
print("p_value = ", p_value)
slope =  0.1570098655993614
intercept =  0.00041737254725253577
r_squared =  0.024651863096276292
p_value =  1.4455956426570483e-05
In [32]:
df_sq['GME'].plot(figsize=(20,10), linewidth = 2, color = ['salmon'])
plt.title("Line Chart for GME Squared Returns", fontsize=30)
plt.ylabel("Squared Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[32]:
Text(0.5, 0, 'Date')
In [33]:
#TTWO
slope, intercept, r_value, p_value, std_err = stats.linregress(df_sq['GME'].shift(1)[1:],df_sq['GME'][1:])

abline_values = [slope * i + intercept for i in df_sq['GME'].shift(1)]

plt.figure(figsize=(20,10))
plt.scatter(df_sq['GME'].shift(1),df_sq['GME'], color = "salmon")
plt.title("GME Day t Squared Return vs Day t-1 Squared Return", fontsize = 30)
plt.ylabel("Day t Squared Return", fontsize = 25)
plt.xlabel("Day t-1 Squared Return", fontsize = 25)
plt.plot(df_sq['GME'].shift(1), abline_values, 'k--', linewidth = 0.75)
Out[33]:
[<matplotlib.lines.Line2D at 0x2b7303474f0>]
In [34]:
#GME
print("slope = ", slope)
print("intercept = ", intercept)
print("r_squared = ", r_value**2)
print("p_value = ", p_value)
slope =  0.3421249089697669
intercept =  0.005190498400515391
r_squared =  0.11704960254460885
p_value =  3.488850436500845e-22
In [35]:
df_sq['ZNGA'].plot(figsize=(20,10), linewidth = 2, color = ['red'])
plt.title("Line Chart for ZNGA Squared Returns", fontsize=30)
plt.ylabel("Squared Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[35]:
Text(0.5, 0, 'Date')
In [36]:
#TTWO
slope, intercept, r_value, p_value, std_err = stats.linregress(df_sq['ZNGA'].shift(1)[1:],df_sq['ZNGA'][1:])

abline_values = [slope * i + intercept for i in df_sq['ZNGA'].shift(1)]

plt.figure(figsize=(20,10))
plt.scatter(df_sq['ZNGA'].shift(1),df_sq['ZNGA'], color = "red")
plt.title("ZNGA Day t Squared Return vs Day t-1 Squared Return", fontsize = 30)
plt.ylabel("Day t Squared Return", fontsize = 25)
plt.xlabel("Day t-1 Squared Return", fontsize = 25)
plt.plot(df_sq['ZNGA'].shift(1), abline_values, 'k--', linewidth = 0.75)
Out[36]:
[<matplotlib.lines.Line2D at 0x2b731c34b80>]
In [37]:
#ZNGA
print("slope = ", slope)
print("intercept = ", intercept)
print("r_squared = ", r_value**2)
print("p_value = ", p_value)
slope =  0.13419125950840238
intercept =  0.0003687236455418311
r_squared =  0.018007328428239405
p_value =  0.0002153479784899844

Ljung Box Test

In [38]:
import statsmodels.api as sm
In [39]:
sm.stats.acorr_ljungbox(df["ATVI"], 20, boxpierce = True, return_df = True)
Out[39]:
lb_stat lb_pvalue bp_stat bp_pvalue
1 11.724247 6.169100e-04 11.677906 6.324666e-04
2 11.814327 2.719891e-03 11.767511 2.784309e-03
3 12.889192 4.882466e-03 12.835296 5.006671e-03
4 14.938805 4.829838e-03 14.868706 4.981422e-03
5 20.362579 1.068294e-03 20.242458 1.125329e-03
6 22.315643 1.061279e-03 22.174937 1.125581e-03
7 23.243610 1.545793e-03 23.091901 1.642908e-03
8 30.927291 1.447517e-04 30.674347 1.605391e-04
9 44.897644 9.637656e-07 44.442231 1.169775e-06
10 46.259138 1.287216e-06 45.782199 1.570581e-06
11 49.158456 8.862751e-07 48.631858 1.101073e-06
12 53.302382 3.639197e-07 52.699348 4.658900e-07
13 53.885645 6.332896e-07 53.271085 8.106119e-07
14 58.035392 2.585732e-07 57.333354 3.424316e-07
15 58.175033 5.179394e-07 57.469866 6.829109e-07
16 58.911883 7.973807e-07 58.189242 1.053371e-06
17 58.911983 1.587186e-06 58.189339 2.084504e-06
18 59.713457 2.276101e-06 58.969694 2.998819e-06
19 59.901109 4.011707e-06 59.152155 5.265800e-06
20 61.830690 3.695312e-06 61.025806 4.935379e-06
In [40]:
sm.stats.acorr_ljungbox(df["TTWO"], 20, boxpierce = True, return_df = True)
Out[40]:
lb_stat lb_pvalue bp_stat bp_pvalue
1 19.115790 1.230228e-05 19.040234 1.279911e-05
2 19.398008 6.134455e-05 19.320965 6.375377e-05
3 19.587088 2.066918e-04 19.508799 2.145515e-04
4 20.086877 4.800588e-04 20.004636 4.983478e-04
5 26.966085 5.791650e-05 26.820400 6.182446e-05
6 27.021549 1.434677e-04 26.875279 1.528087e-04
7 29.646084 1.102527e-04 29.468694 1.188075e-04
8 41.645503 1.578271e-06 41.310018 1.823988e-06
9 56.424626 6.511526e-09 55.874950 8.293145e-09
10 56.450639 1.690087e-08 55.900552 2.142864e-08
11 57.480166 2.713941e-08 56.912445 3.453164e-08
12 58.440099 4.337635e-08 57.854672 5.537884e-08
13 58.632631 9.212604e-08 58.043399 1.172559e-07
14 59.426363 1.478619e-07 58.820399 1.886961e-07
15 59.429692 3.159999e-07 58.823653 4.013177e-07
16 61.222256 3.253318e-07 60.573706 4.188246e-07
17 61.909571 5.069242e-07 61.243816 6.541250e-07
18 61.967875 9.800348e-07 61.300583 1.258958e-06
19 61.968007 1.882042e-06 61.300712 2.405307e-06
20 63.671135 1.896955e-06 62.954473 2.461428e-06
In [41]:
sm.stats.acorr_ljungbox(df["GME"], 20, boxpierce = True, return_df = True)
Out[41]:
lb_stat lb_pvalue bp_stat bp_pvalue
1 0.002544 9.597694e-01 0.002534 9.598489e-01
2 9.642515 8.056649e-03 9.591701 8.263966e-03
3 41.911736 4.188942e-09 41.648346 4.764214e-09
4 93.058228 2.948644e-19 92.390517 4.088392e-19
5 94.239862 8.629687e-19 93.561254 1.198793e-18
6 100.977691 1.568675e-19 100.228065 2.248893e-19
7 110.122814 8.659227e-21 109.264747 1.304575e-20
8 120.851321 2.211650e-22 119.851903 3.557134e-22
9 121.341053 7.100030e-22 120.334538 1.141236e-21
10 122.410604 1.639310e-21 121.387179 2.645801e-21
11 125.438640 1.454029e-21 124.363351 2.396204e-21
12 126.129738 3.683705e-21 125.041702 6.082046e-21
13 139.362426 2.824213e-23 138.012875 5.260871e-23
14 139.739209 7.994475e-23 138.381715 1.487702e-22
15 157.055805 9.512259e-26 155.310455 2.119156e-25
16 163.268478 1.844083e-26 161.375793 4.383174e-26
17 168.017112 6.931905e-27 166.005554 1.733513e-26
18 176.921458 3.900509e-28 174.675267 1.083986e-27
19 179.301107 4.246808e-28 176.989075 1.209992e-27
20 192.951652 2.774067e-30 190.243952 9.472586e-30
In [42]:
sm.stats.acorr_ljungbox(df["ZNGA"], 20, boxpierce = True, return_df = True)
Out[42]:
lb_stat lb_pvalue bp_stat bp_pvalue
1 2.987623 0.083903 2.975814 0.084518
2 3.015914 0.221362 3.003956 0.222689
3 5.004242 0.171487 4.979186 0.173328
4 5.004655 0.286820 4.979596 0.289398
5 8.031026 0.154534 7.978055 0.157449
6 8.781226 0.186261 8.720348 0.189927
7 13.789862 0.055048 13.669594 0.057380
8 18.189941 0.019847 18.011700 0.021139
9 19.964634 0.018132 19.760673 0.019448
10 20.782549 0.022662 20.565656 0.024334
11 27.924847 0.003324 27.585623 0.003745
12 28.382030 0.004862 28.034373 0.005468
13 28.476145 0.007762 28.126628 0.008689
14 29.987911 0.007661 29.606525 0.008642
15 30.234800 0.011102 29.847885 0.012482
16 32.412931 0.008832 31.974360 0.010077
17 32.417751 0.013346 31.979059 0.015138
18 32.930774 0.017015 32.478564 0.019285
19 32.939401 0.024430 32.486952 0.027527
20 32.961769 0.034068 32.508672 0.038171

Ljung Box Test: Squared Returns

In [43]:
sm.stats.acorr_ljungbox(df_sq["ATVI"], 20, boxpierce = True, return_df = True)
Out[43]:
lb_stat lb_pvalue bp_stat bp_pvalue
1 6.972637 8.276545e-03 6.945077 8.405023e-03
2 12.636423 1.803166e-03 12.579014 1.855674e-03
3 16.300118 9.841179e-04 16.218575 1.022773e-03
4 27.059228 1.933826e-05 26.892633 2.089759e-05
5 42.523471 4.615001e-08 42.214254 5.330672e-08
6 46.891209 1.966985e-08 46.535955 2.315366e-08
7 51.133857 8.647040e-09 50.728295 1.039042e-08
8 55.138821 4.148969e-09 54.680493 5.093293e-09
9 60.565808 1.042876e-09 60.028827 1.323638e-09
10 62.108174 1.443249e-09 61.546808 1.845054e-09
11 62.216141 3.583676e-09 61.652926 4.565375e-09
12 62.933422 6.554828e-09 62.356976 8.364739e-09
13 63.167977 1.415713e-08 62.586896 1.802447e-08
14 65.523178 1.233667e-08 64.892449 1.598916e-08
15 66.487505 1.871885e-08 65.835177 2.438143e-08
16 77.169373 5.363740e-10 76.263720 7.785814e-10
17 85.001211 4.895811e-11 83.899504 7.721668e-11
18 85.002511 1.125839e-10 83.900770 1.764529e-10
19 85.368876 2.170505e-10 84.256999 3.395783e-10
20 87.695315 1.869525e-10 86.516004 2.994523e-10
In [44]:
sm.stats.acorr_ljungbox(df_sq["TTWO"], 20, boxpierce = True, return_df = True)
Out[44]:
lb_stat lb_pvalue bp_stat bp_pvalue
1 18.729510 1.506332e-05 18.655480 1.565965e-05
2 23.360132 8.460809e-06 23.261698 8.887640e-06
3 35.349609 1.027696e-07 35.172193 1.120352e-07
4 49.243544 5.194090e-10 48.956295 5.962708e-10
5 50.073015 1.338931e-09 49.778116 1.538500e-09
6 52.459961 1.507004e-09 52.139903 1.747838e-09
7 53.372702 3.129151e-09 53.041822 3.637325e-09
8 54.392637 5.792809e-09 54.048318 6.756137e-09
9 56.133015 7.403259e-09 55.763474 8.709730e-09
10 66.129784 2.462900e-10 65.602190 3.108454e-10
11 66.133428 6.592122e-10 65.605773 8.288188e-10
12 66.973836 1.174268e-09 66.430679 1.481180e-09
13 67.362036 2.446660e-09 66.811207 3.084743e-09
14 67.366471 5.764706e-09 66.815548 7.239817e-09
15 67.544843 1.218157e-08 66.989925 1.526526e-08
16 67.703330 2.510682e-08 67.144654 3.138935e-08
17 67.975552 4.798075e-08 67.410061 5.992355e-08
18 68.078052 9.528632e-08 67.509860 1.186641e-07
19 68.328472 1.740093e-07 67.753352 2.164558e-07
20 68.388169 3.331095e-07 67.811318 4.129901e-07
In [45]:
sm.stats.acorr_ljungbox(df_sq["GME"], 20, boxpierce = True, return_df = True)
Out[45]:
lb_stat lb_pvalue bp_stat bp_pvalue
1 88.953145 4.042753e-21 88.601552 4.829102e-21
2 225.832029 9.145301e-50 224.759071 1.563824e-49
3 284.982267 1.769099e-61 283.519650 3.666449e-61
4 384.992310 4.860204e-82 382.739100 1.490722e-81
5 434.071916 1.338568e-91 431.366061 5.130439e-91
6 445.503483 4.556794e-93 442.677137 1.848798e-92
7 461.778848 1.311108e-95 458.759514 5.836966e-95
8 466.013035 1.368081e-95 462.937914 6.241327e-95
9 476.510183 6.131007e-97 473.282930 3.006318e-96
10 478.161146 2.041215e-96 474.907791 1.010499e-95
11 478.610933 1.163043e-95 475.349874 5.759976e-95
12 479.016004 6.449684e-95 475.747473 3.195113e-94
13 495.925504 1.073377e-97 492.322794 6.247791e-97
14 495.956947 6.669018e-97 492.353574 3.869023e-96
15 536.588672 1.013218e-104 532.075233 9.162822e-104
16 536.901675 5.300734e-104 532.380814 4.790932e-103
17 539.293392 9.770139e-104 534.712659 9.055557e-103
18 544.652802 4.151874e-104 539.930846 4.106436e-103
19 567.173755 4.208923e-108 561.828689 5.623544e-107
20 576.466261 2.591798e-109 570.851848 3.932221e-108
In [46]:
sm.stats.acorr_ljungbox(df_sq["ZNGA"], 20, boxpierce = True, return_df = True)
Out[46]:
lb_stat lb_pvalue bp_stat bp_pvalue
1 13.681638 0.000217 13.627560 0.000223
2 16.811111 0.000224 16.740541 0.000232
3 18.444840 0.000356 18.363507 0.000370
4 23.515870 0.000100 23.394450 0.000106
5 23.661567 0.000252 23.538804 0.000266
6 24.297261 0.000460 24.167798 0.000486
7 24.646686 0.000876 24.513078 0.000925
8 24.888257 0.001624 24.751467 0.001713
9 28.636800 0.000746 28.445683 0.000803
10 31.169033 0.000550 30.937881 0.000601
11 31.255403 0.001003 31.022771 0.001092
12 31.256329 0.001800 31.023680 0.001954
13 31.321485 0.003025 31.087549 0.003274
14 31.847487 0.004211 31.602463 0.004561
15 31.914838 0.006612 31.668305 0.007141
16 31.990044 0.010030 31.741727 0.010803
17 32.015206 0.014983 31.766260 0.016086
18 33.848485 0.013149 33.551230 0.014302
19 33.849296 0.019144 33.552020 0.020743
20 33.912657 0.026722 33.613544 0.028861

ACF Plots: Returns

In [47]:
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df["ATVI"], lags=100, color = "royalblue", ax = ax, title='ACF Plot: ATVI Returns', zero=False)
plt.figsize=(20,10)
In [48]:
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df["TTWO"], lags=100, color = "darkorchid", ax = ax, title='ACF Plot: TTWO Returns',zero=False)
plt.figsize=(20,10)
In [49]:
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df["GME"], lags=100, color = "salmon", ax = ax, title='ACF Plot: GME Returns', zero=False)
plt.figsize=(20,10)
In [50]:
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df["ZNGA"], lags=100, color = "red", ax = ax, title='ACF Plot: ZNGA Returns', zero=False)
plt.figsize=(20,10)

ACF Plots: Squared Returns

In [51]:
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df_sq["ATVI"], lags=100, color = "royalblue", ax = ax, title='ACF Plot: ATVI Squared Returns', zero=False)
plt.figsize=(20,10)
In [52]:
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df_sq["TTWO"], lags=100, color = "darkorchid", ax = ax, title='ACF Plot: TTWO Squared Returns', zero=False)
plt.figsize=(20,10)
In [53]:
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df_sq["GME"], lags=100, color = "salmon", ax = ax, title='ACF Plot: GME Squared Returns', zero=False)
plt.figsize=(20,10)
In [54]:
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df_sq["ZNGA"], lags=100, color = "red", ax = ax, title='ACF Plot: ZNGA Squared Returns', zero=False)
plt.figsize=(20,10)

The standard deviation of returns completely dominates the mean of returns at short horizons; it is impossible to reject statistically zero mean

In [55]:
ATVIh = pd.read_csv("Horizon Analysis/ATVI Horizon.csv",index_col='Date', parse_dates=True, dayfirst=True)
ATVIh.head()
Out[55]:
1D 5D 10D 15D 20D 25D
Date
2018-03-09 NaN NaN NaN NaN NaN NaN
2018-03-12 -0.010127 NaN NaN NaN NaN NaN
2018-03-13 -0.012174 NaN NaN NaN NaN NaN
2018-03-14 -0.022778 NaN NaN NaN NaN NaN
2018-03-15 -0.011382 NaN NaN NaN NaN NaN
In [56]:
ATVIh.mean()
Out[56]:
1D     0.000484
5D     0.000459
10D    0.000677
15D    0.000916
20D    0.001432
25D    0.001147
dtype: float64
In [57]:
ATVIh.std()
Out[57]:
1D     0.021464
5D     0.017110
10D    0.018551
15D    0.019091
20D    0.018821
25D    0.017613
dtype: float64
In [58]:
ATVIh.mean()/ATVIh.std()
Out[58]:
1D     0.022540
5D     0.026800
10D    0.036513
15D    0.048003
20D    0.076105
25D    0.065121
dtype: float64
In [59]:
ATVIh.skew()
Out[59]:
1D    -0.501227
5D    -0.373098
10D   -0.429100
15D   -1.070098
20D   -1.177339
25D   -1.104746
dtype: float64
In [60]:
ATVIh.kurt()
Out[60]:
1D     4.579543
5D     1.035348
10D    0.386235
15D    2.704632
20D    2.856405
25D    2.511845
dtype: float64
In [61]:
TTWOh = pd.read_csv("Horizon Analysis/TTWO Horizon.csv",index_col='Date', parse_dates=True, dayfirst=True)
TTWOh.head()
Out[61]:
1D 5D 10D 15D 20D 25D
Date
2018-03-09 NaN NaN NaN NaN NaN NaN
2018-03-12 -0.004324 NaN NaN NaN NaN NaN
2018-03-13 -0.019632 NaN NaN NaN NaN NaN
2018-03-14 -0.038259 NaN NaN NaN NaN NaN
2018-03-15 -0.003026 NaN NaN NaN NaN NaN
In [62]:
TTWOh.mean()
Out[62]:
1D     0.000727
5D     0.000935
10D    0.001541
15D    0.001988
20D    0.002677
25D    0.002441
dtype: float64
In [63]:
TTWOh.std()
Out[63]:
1D     0.022240
5D     0.016174
10D    0.016108
15D    0.017241
20D    0.016439
25D    0.016259
dtype: float64
In [64]:
TTWOh.mean()/ATVIh.std()
Out[64]:
1D     0.033894
5D     0.054627
10D    0.083089
15D    0.104138
20D    0.142242
25D    0.138610
dtype: float64
In [65]:
TTWOh.skew()
Out[65]:
1D    -0.563923
5D    -0.146820
10D   -0.362759
15D   -0.736790
20D   -0.065137
25D   -0.259765
dtype: float64
In [66]:
TTWOh.kurt()
Out[66]:
1D     5.941578
5D     0.256971
10D    0.030440
15D    0.722660
20D    0.115033
25D   -0.463070
dtype: float64
In [67]:
GMEh = pd.read_csv("Horizon Analysis/GME Horizon.csv",index_col='Date', parse_dates=True, dayfirst=True)
GMEh.head()
Out[67]:
1D 5D 10D 15D 20D 25D
Date
2018-03-09 NaN NaN NaN NaN NaN NaN
2018-03-12 -0.011033 NaN NaN NaN NaN NaN
2018-03-13 0.003851 NaN NaN NaN NaN NaN
2018-03-14 -0.009656 NaN NaN NaN NaN NaN
2018-03-15 -0.009750 NaN NaN NaN NaN NaN
In [68]:
GMEh.mean()
Out[68]:
1D     0.002960
5D     0.007254
10D    0.007496
15D    0.009179
20D    0.005713
25D    0.011613
dtype: float64
In [69]:
GMEh.std()
Out[69]:
1D     0.088775
5D     0.074373
10D    0.067507
15D    0.052925
20D    0.056136
25D    0.075098
dtype: float64
In [70]:
GMEh.mean()/ATVIh.std()
Out[70]:
1D     0.137911
5D     0.423961
10D    0.404042
15D    0.480812
20D    0.303546
25D    0.659314
dtype: float64
In [71]:
GMEh.skew()
Out[71]:
1D     0.702402
5D     2.440694
10D    1.350518
15D    1.008788
20D    1.195678
25D    3.778103
dtype: float64
In [72]:
GMEh.kurt()
Out[72]:
1D     42.585507
5D     15.002822
10D     4.283197
15D     1.916998
20D     1.558343
25D    17.421869
dtype: float64
In [73]:
ZNGAh = pd.read_csv("Horizon Analysis/ZNGA Horizon.csv",index_col='Date', parse_dates=True, dayfirst=True)
ZNGAh.head()
Out[73]:
1D 5D 10D 15D 20D 25D
Date
2018-03-09 NaN NaN NaN NaN NaN NaN
2018-03-12 0.004637 NaN NaN NaN NaN NaN
2018-03-13 -0.013423 NaN NaN NaN NaN NaN
2018-03-14 0.018742 NaN NaN NaN NaN NaN
2018-03-15 0.023592 NaN NaN NaN NaN NaN
In [74]:
ZNGAh.mean()
Out[74]:
1D     0.001570
5D     0.002369
10D    0.003697
15D    0.004644
20D    0.005577
25D    0.005985
dtype: float64
In [75]:
ZNGAh.std()
Out[75]:
1D     0.020577
5D     0.018846
10D    0.019116
15D    0.016729
20D    0.018233
25D    0.016699
dtype: float64
In [76]:
ZNGAh.mean()/ATVIh.std()
Out[76]:
1D     0.073157
5D     0.138467
10D    0.199282
15D    0.243279
20D    0.296307
25D    0.339799
dtype: float64
In [77]:
ZNGAh.skew()
Out[77]:
1D     0.638577
5D    -0.761782
10D   -0.237506
15D   -0.257334
20D    0.517240
25D   -0.313744
dtype: float64
In [78]:
ZNGAh.kurt()
Out[78]:
1D     5.943115
5D     2.860740
10D    0.974513
15D   -0.535778
20D   -0.101633
25D   -0.351036
dtype: float64

EMWA Volatility

In [79]:
def emwa(R, l):
    emwa_vol = pd.DataFrame(index = R.index, columns = R.columns)
    emwa_vol.iloc[0,:] = R.std()
    for i in range(1, len(R)):
        emwa_vol.iloc[i,:] = (l*(emwa_vol.iloc[i-1,:]).pow(2) + (1-l)*(R.iloc[i-1,:]).pow(2)).pow(1/2)
    return emwa_vol
In [80]:
#lambda of 0.94 is generally used
df_emwa = emwa(df, 0.94)
In [81]:
plt.figure(figsize=(30,20))
plt.plot(df_sq["ATVI"], color = "royalblue")
plt.plot(df_emwa["ATVI"].pow(2), color = "k", linewidth = 3)
plt.legend(["ATVI Squared Returns","ATVI EMWA Variance"], prop={'size': 30})
plt.title("ATVI: Squared Returns and EMWA Variance", fontsize = 30)
plt.ylabel("Squared Returns/Variance", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[81]:
Text(0.5, 0, 'Date')
In [82]:
plt.figure(figsize=(30,25))
plt.plot(df_sq["TTWO"], color = "darkorchid")
plt.plot(df_emwa["TTWO"].pow(2), color = "k", linewidth = 3)
plt.legend(["TTWO Squared Returns","TTWO EMWA Variance"], prop={'size': 30})
plt.title("TTWO: Squared Returns and EMWA Variance", fontsize = 30)
plt.ylabel("Squared Returns/Variance", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[82]:
Text(0.5, 0, 'Date')
In [83]:
plt.figure(figsize=(30,20))
plt.plot(df_sq["GME"], color = "salmon")
plt.plot(df_emwa["GME"].pow(2), color = "k", linewidth = 3)
plt.legend(["GME Squared Returns","GME EMWA Variance"], prop={'size': 30})
plt.title("GME: Squared Returns and EMWA Variance", fontsize = 30)
plt.ylabel("Squared Returns/Variance", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[83]:
Text(0.5, 0, 'Date')
In [84]:
plt.figure(figsize=(30,20))
plt.plot(df_sq["ZNGA"], color = "red")
plt.plot(df_emwa["ZNGA"].pow(2), color = "k", linewidth = 3)
plt.legend(["ZNGA Squared Returns","ZNGA EMWA Variance"], prop={'size': 30})
plt.title("ZNGA: Squared Returns and EMWA Variance", fontsize = 30)
plt.ylabel("Squared Returns/Variance", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
Out[84]:
Text(0.5, 0, 'Date')

The Leverage Effect

In [85]:
from scipy.stats.stats import pearsonr   
n = 100

lcorr = pd.DataFrame(index = list(range(1,n+1)), columns = df.columns)

for i in range(1, n+1):
    for j in range(len(lcorr.columns)):
        lcorr.iloc[i-1,j] =  pearsonr(df_sq.iloc[i:,j].values, df.iloc[0:(len(df)-i),j].values)[0]
In [86]:
lcorr
Out[86]:
ATVI TTWO GME ZNGA
1 -0.0602962 -0.0293743 0.162056 -0.0844006
2 0.00374977 -0.0178375 0.253661 -3.4694e-05
3 -0.00991262 0.0351054 0.00476417 -0.0232419
4 -0.0379642 -0.100476 0.292744 -0.0417836
5 -0.0226021 -0.0214785 0.154348 -0.0037548
... ... ... ... ...
96 0.0397679 0.000766766 -0.0379091 -0.00114543
97 -0.0130081 0.0175919 0.0394973 0.0213376
98 -0.00263483 -0.0331699 -0.0079014 0.0182357
99 0.0186803 0.0245768 -0.039834 0.0167534
100 -0.0164536 -0.00224917 0.0181844 0.013683

100 rows × 4 columns

In [209]:
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['ATVI'], linefmt = "k")
plt.setp(baseline, color='royalblue', linewidth=2)
plt.setp(markerline, color = 'royalblue', markersize = 15)
plt.title("TTWO: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
<ipython-input-209-8e3a6ec7c35f>:2: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['ATVI'], linefmt = "k")
Out[209]:
Text(0, 0.5, 'Correlation')
In [206]:
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['TTWO'], linefmt = "k")
plt.setp(baseline, color='darkorchid', linewidth=2)
plt.setp(markerline, color = 'darkorchid', markersize = 15)
plt.title("TTWO: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
<ipython-input-206-cbd795931ec3>:2: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['TTWO'], linefmt = "k")
Out[206]:
Text(0, 0.5, 'Correlation')
In [208]:
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['GME'], linefmt = "k")
plt.setp(baseline, color='salmon', linewidth=2)
plt.setp(markerline, color = 'salmon', markersize = 15)
plt.title("GME: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
<ipython-input-208-75bb5771ef8d>:2: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['GME'], linefmt = "k")
Out[208]:
Text(0, 0.5, 'Correlation')
In [207]:
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['ZNGA'], linefmt = "k")
plt.setp(baseline, color='red', linewidth=2)
plt.setp(markerline, color = 'red', markersize = 15)
plt.title("ZNGA: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
<ipython-input-207-fe3c8d628f7f>:2: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['ZNGA'], linefmt = "k")
Out[207]:
Text(0, 0.5, 'Correlation')
In [91]:
ind = pd.read_csv("Indices.csv",index_col='Date', parse_dates=True, dayfirst=True)
ind.head()
Out[91]:
S&P500 NASDAQ DJIA Russell2000
Date
2018-03-12 -0.000736 0.002097 -0.003592 0.001415
2018-03-13 -0.006384 -0.010240 -0.006838 -0.005643
2018-03-14 -0.005741 -0.001892 -0.010003 -0.004874
2018-03-15 -0.000782 -0.002012 0.004656 -0.004866
2018-03-16 0.001702 0.000033 0.002925 0.005963
In [92]:
indcorr = pd.DataFrame(index = list(range(1,n+1)), columns = ind.columns)

for i in range(1, n+1):
    for j in range(len(indcorr.columns)):
        indcorr.iloc[i-1,j] =  pearsonr(ind.iloc[i:,j].pow(2), ind.iloc[0:(len(ind)-i),j].values)[0]
In [93]:
indcorr.head()
Out[93]:
S&P500 NASDAQ DJIA Russell2000
1 -0.175987 -0.154668 -0.138513 -0.0867125
2 -0.121962 -0.103991 -0.16362 -0.171852
3 -0.0797114 -0.0881729 -0.0488948 -0.0468296
4 -0.223251 -0.179834 -0.233248 -0.234139
5 -0.0122023 -0.0323077 -0.0130409 -0.124108
In [210]:
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['S&P500'], linefmt = "k")
plt.setp(baseline, color='darkgreen', linewidth=2)
plt.setp(markerline, color = 'darkgreen', markersize = 15)
plt.title("S&P 500: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
<ipython-input-210-9901985e0271>:2: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['S&P500'], linefmt = "k")
Out[210]:
Text(0, 0.5, 'Correlation')
In [211]:
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['NASDAQ'], linefmt = "k")
plt.setp(baseline, color='darkgreen', linewidth=2)
plt.setp(markerline, color = 'darkgreen', markersize = 15)
plt.title("NASDAQ: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
<ipython-input-211-2e30b34a4b32>:2: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['NASDAQ'], linefmt = "k")
Out[211]:
Text(0, 0.5, 'Correlation')
In [212]:
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['DJIA'], linefmt = "k")
plt.setp(baseline, color='darkgreen', linewidth=2)
plt.setp(markerline, color = 'darkgreen', markersize = 15)
plt.title("DJIA: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
<ipython-input-212-013c8e7fb696>:2: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['DJIA'], linefmt = "k")
Out[212]:
Text(0, 0.5, 'Correlation')
In [213]:
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['Russell2000'], linefmt = "k")
plt.setp(baseline, color='darkgreen', linewidth=2)
plt.setp(markerline, color = 'darkgreen', markersize = 15)
plt.title("Russell2000: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
<ipython-input-213-5d58fccb4cc6>:2: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['Russell2000'], linefmt = "k")
Out[213]:
Text(0, 0.5, 'Correlation')

Leptokurtic

In [98]:
#Calculate kurtosis
kurto = pd.DataFrame([stats.kurtosis(df[columns].values) for columns in df.columns], index = df.columns, columns = ['Kurtosis'])
In [99]:
kurto
Out[99]:
Kurtosis
ATVI 4.541480
TTWO 5.894463
GME 42.296833
ZNGA 5.896018
In [100]:
df.kurt()
Out[100]:
ATVI     4.579588
TTWO     5.941550
GME     42.585507
ZNGA     5.943115
dtype: float64
In [153]:
from scipy.stats import norm
import matplotlib.pyplot as plt


(mu, sigma) = norm.fit(preprocessing.scale(df["ATVI"]))

plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(df["ATVI"]), 60, density = True, color = 'royalblue')

y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)

plt.axvline(0, color='k', linestyle='--', linewidth = 3)

plt.title("Histogram of Returns of ATVI", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
Out[153]:
<matplotlib.legend.Legend at 0x2b743a56340>
In [154]:
(mu, sigma) = norm.fit(preprocessing.scale(df["TTWO"]))

plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(df["TTWO"]), 60, density = True, color = 'darkorchid')

y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)

plt.axvline(0, color='k', linestyle='--', linewidth = 3)

plt.title("Histogram of Returns of TTWO", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
Out[154]:
<matplotlib.legend.Legend at 0x2b745246f70>
In [155]:
(mu, sigma) = norm.fit(preprocessing.scale(df["GME"]))

plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(df["GME"]), 60, density = True, color = 'salmon')

y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)

plt.axvline(0, color='k', linestyle='--', linewidth = 3)

plt.title("Histogram of Returns of GME", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
Out[155]:
<matplotlib.legend.Legend at 0x2b7452f02e0>
In [156]:
(mu, sigma) = norm.fit(preprocessing.scale(df["ZNGA"]))

plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(df["ZNGA"]), 60, density = True, color = 'red')

y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)

plt.axvline(0, color='k', linestyle='--', linewidth = 3)

plt.title("Histogram of Returns of ZNGA", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
Out[156]:
<matplotlib.legend.Legend at 0x2b7452e8310>

Skew and FX Markets

In [105]:
rskew = pd.DataFrame([stats.skew(df[columns].values) for columns in df.columns], index = df.columns, columns = ['Skewness'])
In [106]:
rskew
Out[106]:
Skewness
ATVI -0.500237
TTWO -0.562803
GME 0.701010
ZNGA 0.637311
In [107]:
fxdf = pd.read_csv("FX Data.csv")
fxdf['Date'] = pd.to_datetime(fxdf['Date'])
fxdf = fxdf.set_index(['Date'])
fxdf.head()
Out[107]:
USDGBP USDEUR USDJPY USDCHF
Date
2018-12-03 -0.002404 -0.001352 -0.002166 -0.002250
2018-03-13 -0.004041 -0.004450 0.001502 -0.003700
2018-03-14 0.000140 0.001857 -0.002442 0.000847
2018-03-15 0.001674 0.005058 0.000188 0.006855
2018-03-16 -0.000558 0.001230 -0.003108 0.000630
In [108]:
fxskew = pd.DataFrame([stats.skew(fxdf[columns].values) for columns in fxdf.columns], index = fxdf.columns, columns = ['Skewness'])
In [109]:
fxskew
Out[109]:
Skewness
USDGBP 0.151076
USDEUR 0.349265
USDJPY 1.003576
USDCHF 0.152228
In [157]:
(mu, sigma) = norm.fit(preprocessing.scale(fxdf["USDGBP"]))

plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(fxdf["USDGBP"]), 60, density = True, color = 'cadetblue')

y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)

plt.axvline(0, color='k', linestyle='--', linewidth = 3)


plt.title("Histogram of Returns of USDGBP", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
Out[157]:
<matplotlib.legend.Legend at 0x2b7454e4520>
In [158]:
(mu, sigma) = norm.fit(preprocessing.scale(fxdf["USDEUR"]))

plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(fxdf["USDEUR"]), 60, density = True, color = 'cadetblue')

y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)

plt.axvline(0, color='k', linestyle='--', linewidth = 3)


plt.title("Histogram of Returns of USDEUR", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
Out[158]:
<matplotlib.legend.Legend at 0x2b7454ab9d0>
In [159]:
(mu, sigma) = norm.fit(preprocessing.scale(fxdf["USDJPY"]))

plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(fxdf["USDJPY"]), 60, density = True, color = 'cadetblue')

y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)

plt.axvline(0, color='k', linestyle='--', linewidth = 3)


plt.title("Histogram of Returns of USDJPY", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
Out[159]:
<matplotlib.legend.Legend at 0x2b7455c7f70>
In [160]:
(mu, sigma) = norm.fit(preprocessing.scale(fxdf["USDCHF"]))

plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(fxdf["USDCHF"]), 60, density = True, color = 'cadetblue')

y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)

plt.axvline(0, color='k', linestyle='--', linewidth = 3)


plt.title("Histogram of Returns of USDCHF", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
Out[160]:
<matplotlib.legend.Legend at 0x2b7420cc3d0>

JB Statistic

In [114]:
rjbs = pd.DataFrame([stats.jarque_bera(preprocessing.scale(df[columns].values)).statistic for columns in df.columns], index = df.columns, columns = ['JB Statistic'])
In [115]:
rjbs["p-value"] = [stats.jarque_bera(preprocessing.scale(df[columns].values)).pvalue for columns in df.columns]
In [116]:
rjbs
Out[116]:
JB Statistic p-value
ATVI 682.119721 0.0
TTWO 1135.868351 0.0
GME 56490.739393 0.0
ZNGA 1147.728353 0.0
In [117]:
fxkurto = pd.DataFrame([stats.kurtosis(fxdf[columns].values) for columns in fxdf.columns], index = fxdf.columns, columns = ['Kurtosis'])
In [118]:
fxkurto
Out[118]:
Kurtosis
USDGBP 4.716171
USDEUR 2.271104
USDJPY 10.271412
USDCHF 2.045400
In [119]:
#JB Statistic for FX Return data
fxjbs = pd.DataFrame([stats.jarque_bera(preprocessing.scale(fxdf[columns].values)).statistic for columns in fxdf.columns], index = fxdf.columns, columns = ['JB Statistic'])
In [120]:
fxjbs["p-value"] = [stats.jarque_bera(preprocessing.scale(fxdf[columns].values)).pvalue for columns in fxdf.columns]
In [121]:
fxjbs
Out[121]:
JB Statistic p-value
USDGBP 730.493541 0.0
USDEUR 184.666606 0.0
USDJPY 3582.561905 0.0
USDCHF 139.872499 0.0

Multivariate Stylized Facts

In [122]:
df.corr()
Out[122]:
ATVI TTWO GME ZNGA
ATVI 1.000000 0.652335 0.022086 0.528495
TTWO 0.652335 1.000000 0.033949 0.475336
GME 0.022086 0.033949 1.000000 0.000530
ZNGA 0.528495 0.475336 0.000530 1.000000

Little evidence of cross-correlation except for concurrent (i.e. contemporaneous retunrs)

In [123]:
from scipy.stats.stats import pearsonr   


def lag_cross_corr(x,y,n = 100):
    lcross_cov = pd.DataFrame(index = list(range(1,n+1)), columns = [x.name + "-" + y.name])
    
    for i in range(1, n+1):
        lcross_cov.iloc[i-1,0] =  pearsonr(x[i:], y[0:(len(y)-i)])[0]
    
    return lcross_cov
In [124]:
cross_corr_lag = pd.DataFrame(index = list(range(1,101)), columns = ["ATVI-TTWO","ATVI-GME","ATVI-ZNGA","TTWO-ATVI","TTWO-GME","TTWO-ZNGA","GME-ATVI","GME-TTWO","GME-ZNGA","ZNGA-ATVI","ZNGA-TTWO","ZNGA-GME"])

for name in cross_corr_lag.columns:
    s1, s2 = name.split("-")
    cross_corr_lag[name] = lag_cross_corr(df[s1],df[s2])
In [125]:
cross_corr_lag
Out[125]:
ATVI-TTWO ATVI-GME ATVI-ZNGA TTWO-ATVI TTWO-GME TTWO-ZNGA GME-ATVI GME-TTWO GME-ZNGA ZNGA-ATVI ZNGA-TTWO ZNGA-GME
1 -0.125664 -0.0745565 -0.141662 -0.0757928 -0.0445637 -0.141079 -0.0229858 -0.0572366 -0.0343522 -0.035087 -0.107496 -0.0922157
2 -0.0119322 0.0610391 -0.0240223 -0.00117794 0.0376965 -0.000859128 -0.0517061 -0.0288712 -0.0241979 0.0163011 0.0238739 0.00269631
3 0.0162593 -0.048595 -0.00280261 -0.00838849 -0.0139115 -0.0430281 -0.0282508 -0.0514863 0.0122684 -0.0112451 -0.0235664 0.0264737
4 -0.0437647 0.00152134 -0.0738587 -0.00762952 0.0216359 -0.025461 0.0361534 0.0591315 0.0336008 0.00881393 -0.036304 -0.0149631
5 -0.0963069 -0.000293847 -0.0225743 -0.100305 0.00430058 -0.0691601 0.013965 0.0241998 0.00296772 -0.0941376 -0.076029 -0.0524275
... ... ... ... ... ... ... ... ... ... ... ... ...
96 0.000299054 0.0503685 0.0172233 0.0274606 0.00208801 0.039743 -0.0101218 -0.0379362 -0.0201508 0.0335853 0.0123552 0.0553428
97 0.0156189 0.0135639 -0.00820984 0.0407784 0.00295094 0.0184916 -0.018198 -0.0343659 0.0017765 0.0141503 0.0179175 0.0272041
98 -0.0413799 0.02433 -0.0564279 -0.0542673 0.026732 -0.0610528 -0.0461553 -0.0111876 -0.0360567 -0.0414853 0.000250528 0.0855278
99 0.0347744 -0.0228896 -0.0268517 0.0516739 -0.00648721 -0.0058389 0.0339475 0.0385131 0.0463209 0.0219012 0.0158455 -0.0111982
100 -0.0365463 -0.0757909 -0.0302108 -0.0286239 -0.0891698 -0.044451 -0.00664473 0.00892416 0.00210203 -0.00993913 -0.0294643 -0.052404

100 rows × 12 columns

In [126]:
plt.figure(figsize=(30,20))
plt.plot(cross_corr_lag['ATVI-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['ATVI-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['ATVI-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("ATVI Returns vs Other Stocks Lagged Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['ATVI-TTWO', 'ATVI-GME','ATVI-ZNGA'], prop={'size': 30})
Out[126]:
<matplotlib.legend.Legend at 0x2b74171ceb0>
In [127]:
plt.figure(figsize=(30,20))
plt.plot(cross_corr_lag['TTWO-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['TTWO-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['TTWO-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("TTWO Returns vs Other Stocks Lagged Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['TTWO-ATVI', 'TTWO-GME','TTWO-ZNGA'], prop={'size': 30})
Out[127]:
<matplotlib.legend.Legend at 0x2b74179db50>
In [128]:
plt.figure(figsize=(30,20))
plt.plot(cross_corr_lag['GME-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['GME-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['GME-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("GME Returns vs Other Stocks Lagged Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['GME-ATVI', 'GME-TTWO','GME-ZNGA'], prop={'size': 30})
Out[128]:
<matplotlib.legend.Legend at 0x2b7417de940>
In [129]:
plt.figure(figsize=(30,20))
plt.plot(cross_corr_lag['ZNGA-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['ZNGA-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['ZNGA-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("ZNGA Returns vs Other Stocks Lagged Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['ZNGA-ATVI', 'ZNGA-TTWO','ZNGA-GME'], prop={'size': 30})
Out[129]:
<matplotlib.legend.Legend at 0x2b741879d90>

Multivariate series of absolute returns show profound evidence of cross correlations.

In [130]:
df_abs = df.abs()
In [131]:
df.head()
Out[131]:
ATVI TTWO GME ZNGA
Date
2018-03-12 -0.010127 -0.004324 -0.011033 0.004637
2018-03-13 -0.012174 -0.019632 0.003851 -0.013423
2018-03-14 -0.022778 -0.038259 -0.009656 0.018742
2018-03-15 -0.011382 -0.003026 -0.009750 0.023592
2018-03-16 -0.023440 -0.014895 0.007159 -0.010417
In [132]:
df_abs.head()
Out[132]:
ATVI TTWO GME ZNGA
Date
2018-03-12 0.010127 0.004324 0.011033 0.004637
2018-03-13 0.012174 0.019632 0.003851 0.013423
2018-03-14 0.022778 0.038259 0.009656 0.018742
2018-03-15 0.011382 0.003026 0.009750 0.023592
2018-03-16 0.023440 0.014895 0.007159 0.010417
In [133]:
cross_corr_abs_lag = pd.DataFrame(index = list(range(1,101)), columns = ["ATVI-TTWO","ATVI-GME","ATVI-ZNGA","TTWO-ATVI","TTWO-GME","TTWO-ZNGA","GME-ATVI","GME-TTWO","GME-ZNGA","ZNGA-ATVI","ZNGA-TTWO","ZNGA-GME"])

for name in cross_corr_lag.columns:
    s1, s2 = name.split("-")
    cross_corr_abs_lag[name] = lag_cross_corr(df_abs[s1],df_abs[s2])
In [134]:
cross_corr_abs_lag
Out[134]:
ATVI-TTWO ATVI-GME ATVI-ZNGA TTWO-ATVI TTWO-GME TTWO-ZNGA GME-ATVI GME-TTWO GME-ZNGA ZNGA-ATVI ZNGA-TTWO ZNGA-GME
1 0.101058 0.0399928 0.152153 0.165405 -0.000313093 0.284595 -0.00231497 0.015411 0.0341978 0.117311 0.149311 0.0537437
2 0.0923449 -0.00818433 0.127619 0.141955 -0.00029237 0.141073 0.0162825 0.0166249 0.0705412 0.102614 0.113774 0.00990064
3 0.144485 0.0814249 0.121089 0.0922014 0.0418772 0.138499 0.00362417 0.000304226 0.0682944 0.069224 0.103329 0.0663065
4 0.136651 -0.0132206 0.0879425 0.196091 -0.0131118 0.122927 0.0202494 0.0359308 0.13315 0.138599 0.0746709 0.0507914
5 0.118551 0.0793171 0.113054 0.140522 0.0659633 0.0893007 0.024862 -0.00784216 0.083575 0.0383044 0.0461003 0.0995806
... ... ... ... ... ... ... ... ... ... ... ... ...
96 -0.0455725 -0.0495293 -0.0845343 -0.136138 -0.0107532 -0.0483502 0.0122017 -0.0180174 -0.0235355 -0.101004 -0.0463539 -0.0135549
97 -0.0351125 -0.0405265 -0.0149354 -0.053758 -0.0473603 -0.0768724 -0.0207039 -0.010131 0.0062818 -0.114276 -0.0828632 0.0104629
98 -0.043141 -0.0156289 -0.0526287 0.0165881 -0.064343 -0.0315159 0.0396412 0.0259127 0.0106198 -0.0398145 -0.0565556 0.0135349
99 -0.0111013 -0.0255062 -0.0358079 -0.0512524 -0.00906053 0.0136506 0.0105219 -0.00421392 -0.0202801 -0.0946522 -0.0303772 0.0439419
100 0.00320464 -0.0304361 -0.0268869 -0.0914898 0.0168722 -0.0177973 -0.0371226 -0.0460125 -0.055364 -0.0712749 -0.036394 0.0181798

100 rows × 12 columns

In [135]:
plt.figure(figsize=(30,20))
plt.plot(cross_corr_abs_lag['ATVI-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['ATVI-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['ATVI-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("ATVI Absolute Returns vs Other Stocks Lagged Absolute Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['ATVI-TTWO', 'ATVI-GME','ATVI-ZNGA'], prop={'size': 30})
Out[135]:
<matplotlib.legend.Legend at 0x2b74199ca30>
In [136]:
plt.figure(figsize=(30,20))
plt.plot(cross_corr_abs_lag['TTWO-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['TTWO-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['TTWO-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("TTWO Absolute Returns vs Other Stocks Lagged Absolute Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['TTWO-ATVI', 'TTWO-GME','TTWO-ZNGA'], prop={'size': 30})
Out[136]:
<matplotlib.legend.Legend at 0x2b741a01dc0>
In [137]:
plt.figure(figsize=(30,20))
plt.plot(cross_corr_abs_lag['GME-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['GME-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['GME-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("GME Absolute Returns vs Other Stocks Lagged Absolute Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['GME-ATVI', 'GME-TTWO','GME-ZNGA'], prop={'size': 30})
Out[137]:
<matplotlib.legend.Legend at 0x2b741a6e850>
In [138]:
plt.figure(figsize=(30,20))
plt.plot(cross_corr_abs_lag['ZNGA-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['ZNGA-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['ZNGA-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("ZNGA Absolute Returns vs Other Stocks Lagged Absolute Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['ZNGA-ATVI', 'ZNGA-TTWO','ZNGA-GME'], prop={'size': 30})
Out[138]:
<matplotlib.legend.Legend at 0x2b741ad7bb0>

Little evidence of cross-correlation except for concurrent (i.e. contemporaneous retunrs): Stem plots for correlations

In [255]:
fig, ax = plt.subplots(3, 2, figsize=(15,15))
fig.suptitle('ATVI: Multivariate Correlations', y = 1)

colors = ['darkorchid','salmon','red']

col1_title = " Lagged Returns Correlations"
col2_title = " Lagged Absolute Returns Correlations"

ATVI_cross_corr_lag = pd.concat([cross_corr_lag['ATVI-TTWO'], cross_corr_lag['ATVI-GME'], cross_corr_lag['ATVI-ZNGA']], axis = 1)
ATVI_cross_corr_abs_lag = pd.concat([cross_corr_abs_lag['ATVI-TTWO'], cross_corr_abs_lag['ATVI-GME'], cross_corr_abs_lag['ATVI-ZNGA']], axis = 1)

for j,i in enumerate([0,1,2]):
    markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ATVI_cross_corr_lag.iloc[:,i].values, linefmt = "k")   
    ax[i,0].set_title(ATVI_cross_corr_lag.columns[j] + col1_title, fontsize = 20)
    ax[i,0].set_xlabel("Lag", fontsize = 15)
    ax[i,0].set_ylabel("Correlation", fontsize = 15)
    plt.setp(baseline, color= colors[j], linewidth=2)
    plt.setp(markerline, color = colors[j], markersize = 7.5)
    
    markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ATVI_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")   
    ax[i,1].set_title(ATVI_cross_corr_abs_lag.columns[j] + col2_title, fontsize = 20)
    ax[i,1].set_xlabel("Lag", fontsize = 15)
    ax[i,1].set_ylabel("Correlation", fontsize = 15)
    plt.setp(baseline, color= colors[j], linewidth=2)
    plt.setp(markerline, color = colors[j], markersize = 7.5)
    
fig.tight_layout()
<ipython-input-255-8168a57d601b>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ATVI_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-255-8168a57d601b>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ATVI_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-255-8168a57d601b>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ATVI_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-255-8168a57d601b>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ATVI_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-255-8168a57d601b>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ATVI_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-255-8168a57d601b>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ATVI_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
In [256]:
fig, ax = plt.subplots(3, 2, figsize=(15,15))
fig.suptitle('TTWO: Multivariate Correlations'+'\n', y = 1)

colors = ['royalblue','salmon','red']

col1_title = " Lagged Returns Correlations"
col2_title = " Lagged Absolute Returns Correlations"

TTWO_cross_corr_lag = pd.concat([cross_corr_lag['TTWO-ATVI'], cross_corr_lag['TTWO-GME'], cross_corr_lag['TTWO-ZNGA']], axis = 1)
TTWO_cross_corr_abs_lag = pd.concat([cross_corr_abs_lag['TTWO-ATVI'], cross_corr_abs_lag['TTWO-GME'], cross_corr_abs_lag['TTWO-ZNGA']], axis = 1)

for j,i in enumerate([0,1,2]):
    markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), TTWO_cross_corr_lag.iloc[:,i].values, linefmt = "k")   
    ax[i,0].set_title(TTWO_cross_corr_lag.columns[j] + col1_title, fontsize = 20)
    ax[i,0].set_xlabel("Lag", fontsize = 15)
    ax[i,0].set_ylabel("Correlation", fontsize = 15)
    plt.setp(baseline, color= colors[j], linewidth=2)
    plt.setp(markerline, color = colors[j], markersize = 7.5)
    
    markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), TTWO_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")   
    ax[i,1].set_title(TTWO_cross_corr_abs_lag.columns[j] + col2_title, fontsize = 20)
    ax[i,1].set_xlabel("Lag", fontsize = 15)
    ax[i,1].set_ylabel("Correlation", fontsize = 15)
    plt.setp(baseline, color= colors[j], linewidth=2)
    plt.setp(markerline, color = colors[j], markersize = 7.5)
    
fig.tight_layout()
<ipython-input-256-c9c03cfc5dcb>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), TTWO_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-256-c9c03cfc5dcb>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), TTWO_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-256-c9c03cfc5dcb>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), TTWO_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-256-c9c03cfc5dcb>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), TTWO_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-256-c9c03cfc5dcb>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), TTWO_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-256-c9c03cfc5dcb>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), TTWO_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
In [259]:
fig, ax = plt.subplots(3, 2, figsize=(15,15))
fig.suptitle('GME: Multivariate Correlations'+'\n', y = 1)

colors = ['royalblue','darkorchid','red']

col1_title = " Lagged Returns Correlations"
col2_title = " Lagged Absolute Returns Correlations"

GME_cross_corr_lag = pd.concat([cross_corr_lag['GME-ATVI'], cross_corr_lag['GME-TTWO'], cross_corr_lag['GME-ZNGA']], axis = 1)
GME_cross_corr_abs_lag = pd.concat([cross_corr_abs_lag['GME-ATVI'], cross_corr_abs_lag['GME-TTWO'], cross_corr_abs_lag['GME-ZNGA']], axis = 1)

for j,i in enumerate([0,1,2]):
    markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), GME_cross_corr_lag.iloc[:,i].values, linefmt = "k")   
    ax[i,0].set_title(GME_cross_corr_lag.columns[j] + col1_title, fontsize = 20)
    ax[i,0].set_xlabel("Lag", fontsize = 15)
    ax[i,0].set_ylabel("Correlation", fontsize = 15)
    plt.setp(baseline, color= colors[j], linewidth=2)
    plt.setp(markerline, color = colors[j], markersize = 7.5)
    
    markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), GME_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")   
    ax[i,1].set_title(GME_cross_corr_abs_lag.columns[j] + col2_title, fontsize = 20)
    ax[i,1].set_xlabel("Lag", fontsize = 15)
    ax[i,1].set_ylabel("Correlation", fontsize = 15)
    plt.setp(baseline, color= colors[j], linewidth=2)
    plt.setp(markerline, color = colors[j], markersize = 7.5)
    
fig.tight_layout()
<ipython-input-259-fa62a2aed6f6>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), GME_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-259-fa62a2aed6f6>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), GME_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-259-fa62a2aed6f6>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), GME_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-259-fa62a2aed6f6>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), GME_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-259-fa62a2aed6f6>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), GME_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-259-fa62a2aed6f6>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), GME_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
In [258]:
fig, ax = plt.subplots(3, 2, figsize=(15,15))
fig.suptitle('ZNGA: Multivariate Correlations'+'\n', y = 1)

colors = ['royalblue','darkorchid','salmon']

col1_title = " Lagged Returns Correlations"
col2_title = " Lagged Absolute Returns Correlations"

ZNGA_cross_corr_lag = pd.concat([cross_corr_lag['ZNGA-ATVI'], cross_corr_lag['ZNGA-TTWO'], cross_corr_lag['ZNGA-GME']], axis = 1)
ZNGA_cross_corr_abs_lag = pd.concat([cross_corr_abs_lag['ZNGA-ATVI'], cross_corr_abs_lag['ZNGA-TTWO'], cross_corr_abs_lag['ZNGA-GME']], axis = 1)

for j,i in enumerate([0,1,2]):
    markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ZNGA_cross_corr_lag.iloc[:,i].values, linefmt = "k")   
    ax[i,0].set_title(ZNGA_cross_corr_lag.columns[j] + col1_title, fontsize = 20)
    ax[i,0].set_xlabel("Lag", fontsize = 15)
    ax[i,0].set_ylabel("Correlation", fontsize = 15)
    plt.setp(baseline, color= colors[j], linewidth=2)
    plt.setp(markerline, color = colors[j], markersize = 7.5)
    
    markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ZNGA_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")   
    ax[i,1].set_title(ZNGA_cross_corr_abs_lag.columns[j] + col2_title, fontsize = 20)
    ax[i,1].set_xlabel("Lag", fontsize = 15)
    ax[i,1].set_ylabel("Correlation", fontsize = 15)
    plt.setp(baseline, color= colors[j], linewidth=2)
    plt.setp(markerline, color = colors[j], markersize = 7.5)
    
fig.tight_layout()
<ipython-input-258-9ec9ba82eb9d>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ZNGA_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-258-9ec9ba82eb9d>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ZNGA_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-258-9ec9ba82eb9d>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ZNGA_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-258-9ec9ba82eb9d>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ZNGA_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-258-9ec9ba82eb9d>:13: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ZNGA_cross_corr_lag.iloc[:,i].values, linefmt = "k")
<ipython-input-258-9ec9ba82eb9d>:20: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ZNGA_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")

Extreme returns in one series often coincide with extreme returns in several other series

In [139]:
df_norm = (df - df.mean())/df.std()
In [140]:
df_ext = df_norm[(df_norm.abs() > 2).any(1)]
In [141]:
er2 = pd.read_csv("Excess returns 2.csv",index_col='Date', parse_dates=True, dayfirst=True)
In [152]:
plt.figure(figsize=(30,20))
plt.scatter(x = er2.index, y = er2['ATVI'], color = 'royalblue', s = 300)
plt.scatter(x = er2.index, y = er2['TTWO'], color = 'darkorchid', s = 300)
plt.scatter(x = er2.index, y = er2['GME'], color = 'salmon', s = 300)
plt.scatter(x = er2.index, y = er2['ZNGA'], color = 'red', s = 300)
plt.axhline(y=0, color='k', linestyle='--')
plt.axvline(pd.to_datetime('2020-03-13'), color='darkred', linestyle='--', linewidth = 3)

plt.axvline(pd.to_datetime('2018-03-27'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2018-11-09'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-04'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-12'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-16'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-20'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-26'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-08-11'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2021-01-27'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)

plt.title("Extreme Normalized Returns of Stocks")
plt.ylabel("Standard Deviations")
plt.xlabel("Date")
plt.legend(["_0","Movement in 4 Stocks ","Movement in 3 Stocks"])
<ipython-input-152-7ac6652fc926>:22: UserWarning: The handle <matplotlib.lines.Line2D object at 0x000002B7424996D0> has a label of '_0' which cannot be automatically added to the legend.
  plt.legend(["_0","Movement in 4 Stocks ","Movement in 3 Stocks"])
Out[152]:
<matplotlib.legend.Legend at 0x2b742449580>

Correlations change with time

In [143]:
n = [0,126,252,378,504,630,757]

for i in range(6):
    print(df.iloc[n[i]:n[i+1],:].corr())
    print("\n")
          ATVI      TTWO       GME      ZNGA
ATVI  1.000000  0.628932  0.035522  0.523203
TTWO  0.628932  1.000000  0.005169  0.444282
GME   0.035522  0.005169  1.000000 -0.051644
ZNGA  0.523203  0.444282 -0.051644  1.000000


          ATVI      TTWO       GME      ZNGA
ATVI  1.000000  0.706353  0.250512  0.432642
TTWO  0.706353  1.000000  0.157014  0.452733
GME   0.250512  0.157014  1.000000  0.079636
ZNGA  0.432642  0.452733  0.079636  1.000000


          ATVI      TTWO       GME      ZNGA
ATVI  1.000000  0.548185  0.119580  0.469280
TTWO  0.548185  1.000000  0.015786  0.515528
GME   0.119580  0.015786  1.000000  0.078085
ZNGA  0.469280  0.515528  0.078085  1.000000


          ATVI      TTWO       GME      ZNGA
ATVI  1.000000  0.469558  0.212506  0.489584
TTWO  0.469558  1.000000  0.279933  0.506546
GME   0.212506  0.279933  1.000000  0.110767
ZNGA  0.489584  0.506546  0.110767  1.000000


          ATVI      TTWO       GME      ZNGA
ATVI  1.000000  0.752284  0.085365  0.702696
TTWO  0.752284  1.000000  0.220483  0.605279
GME   0.085365  0.220483  1.000000  0.143165
ZNGA  0.702696  0.605279  0.143165  1.000000


          ATVI      TTWO       GME      ZNGA
ATVI  1.000000  0.637316 -0.134629  0.554724
TTWO  0.637316  1.000000 -0.096784  0.340932
GME  -0.134629 -0.096784  1.000000 -0.094611
ZNGA  0.554724  0.340932 -0.094611  1.000000


In [ ]: